package cn.ljw.mybatis;

import lombok.Data;

import java.sql.Connection;

/**
 * @author 一朝风月
 * @date 2024/9/21 22:58
 * @Code 面向注解面向卿，终无解释再无你
 * @description 默认的会话工厂实现接口
 */

public class WinterFlySqlSessionFactory implements SqlSessionFactory{
    private final Configuration configuration;
    public WinterFlySqlSessionFactory(Configuration configuration) {
        this.configuration = configuration;
    }
    @Override
    public SqlSession openSession() {
    return new WinterFlySqlSession(configuration.connection, configuration.mapperElement);
    }

    @Override
    public SqlSession openSession(boolean autoCommit) {
         return new WinterFlySqlSession(configuration.connection, configuration.mapperElement, autoCommit);
    }

    @Override
    public SqlSession openSession(Connection connection) {
        if(connection != null)
            return new WinterFlySqlSession(connection, configuration.mapperElement);
         return openSession();
    }
}
